package com.mj.app.health.activity;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mj.app.health.R;
import com.mj.app.health.base.BaseActivity;
import com.mj.app.health.defination.IntentKeys;

import java.util.List;

import butterknife.BindView;

/**
 * ========================================
 * Created by 郝赫 on 2017/10/12.
 * ========================================
 */

public class WebNormalActivity extends BaseActivity {

    @BindView(R.id.com_back)
    ImageView comBack;
    @BindView(R.id.com_title)
    TextView comTitle;
    @BindView(R.id.com_btn)
    TextView comBtn;
    @BindView(R.id.com_title_rl)
    RelativeLayout comTitleRl;
    @BindView(R.id.web)
    WebView web;

    @Override
    protected int setLayoutId() {
        return R.layout.activity_web_normal;
    }

    @Override
    protected void init() {

        Bundle b = getIntent().getBundleExtra(IntentKeys.BUNDLE_KEY);

        if(b != null){

            String title = b.getString(IntentKeys.WEB_TITLE);
            String content = b.getString(IntentKeys.WEB_CONTENT);

            comTitle.setText(title);
            loadWeb(content);
        }

        comBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                back();
            }
        });
    }

    private void loadWeb(String webContent) {

//        String fontSize = String.valueOf(getResources().getDimension(R.dimen.dm020))+";";
        String css = "<style type=\"text/css\"> img {" +
                "width:100%;" +//限定图片宽度填充屏幕
                "height:auto;" +//限定图片高度自动
                "}" +
                "body {" +
                "margin-right:0px;" +//限定网页中的文字右边距为15px(可根据实际需要进行行管屏幕适配操作)
                "margin-left:0px;" +//限定网页中的文字左边距为15px(可根据实际需要进行行管屏幕适配操作)
                "margin-top:0px;" +//限定网页中的文字上边距为15px(可根据实际需要进行行管屏幕适配操作)
//                "font-size:" +fontSize+//限定网页中文字的大小为40px,请务必根据各种屏幕分辨率进行适配更改
                "word-wrap:break-word;"+//允许自动换行(汉字网页应该不需要这一属性,这个用来强制英文单词换行,类似于word/wps中的西文换行)
                "}" +
                "</style>";


        String html = "<html><header>" + css + "</header><body>" + webContent + "</body></html>";
        web.loadDataWithBaseURL(null, html, "text/html", "utf-8", null);
    }
}
